module.exports = function(grunt) {

    grunt.initConfig({
        htmlConvert: {
            options: {
                // custom options, see below
                base: "release"
            },
            mytemplate: {
                src: ['release/tpl/*.tpl.html'],
                dest: 'release/js/templates.js'
            },
        },
        concat: {
            options: {
                separator: ";\n",
                stripBanners: true,
            },
            dist: {
                src: ['release/js/*.js', 'release/js/*/*.js'],
                dest:  'www/script.js',
            }
        },

        uglify: {
            options: {
                compress: {
                    drop_console: true // <-
                }
            },
            my_target: {
                files: {
                     'www/script.min.js': [ 'www/script.js']
                }
            }
        },
        copy: {
            css: {
                expand: true,
                cwd: 'release/css/',
                src: '**',
                dest:  'www/css/'
            },
            images: {
                expand: true,
                cwd: 'release/images/',
                src: ['*.jpg', '*.png', '*.gif'],
                dest:  'www/images/',
            },
            kendo: {
                expand: true,
                cwd: 'release/kendo/',
                src: '**',
                dest:  'www/kendo/'
            },
            src: {
                expand: true,
                cwd: 'release/src/',
                src: '**',
                dest:  'www/src/'
            },
		
            other: {
                expand: true,
                cwd: 'release/',
                src: ['*.xml', '*.html', '*.png', '*.js'],
                dest:  'www/',
            },
		
            index: {
                expand: true,
                cwd: 'release/',
                src: ['index.html'],
                dest:  'www/',
                options: {
                    process: function(content, srcpath) {
                        console.log(srcpath, srcpath.split('/').pop());
                        console.log('replace');
                        content = content.replace(/STARTRELEASE(.|\r|\n)+ENDRELEASE/, "");
                        content = content.replace("<!--SCRIPT", "");
                        content = content.replace("SCRIPT-->", "");
                        return content;
                    }
                }
            }
        },
        clean: ["dist"]
    });


    grunt.loadNpmTasks('grunt-html-convert');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-clean');




    grunt.registerTask('test', ['htmlConvert', 'concat']);
    grunt.registerTask('default', ['clean', 'htmlConvert', 'copy', 'concat', 'uglify']);

};
